const setButtons = require('./simple-config/buttons')
const setTable = require('./simple-config/table')
const queryForm = require('./simple-config/queryForm')
const addForm = require('./simple-config/addForm')
const editForm = require('./simple-config/editForm')
const globe = require('./simple-config/globe')

const defaultConfig = require('./simple-config/default')

const functions = [setButtons, setTable, queryForm,addForm,editForm,globe]

module.exports =  function (config) {
  const result = {}

  functions.forEach((func) => func.call(null, config, result))
  replaceObjectProperties(result,defaultConfig)
  return defaultConfig;
}


function replaceObjectProperties(A, B) {
  for (let key in A) {
      if (A.hasOwnProperty(key)) {
          if (typeof B[key] === 'object' && !Array.isArray(B[key]) && B[key]!== null && typeof A[key] === 'object' && !Array.isArray(A[key]) && A[key]!== null) {
            // 如果属性值都是对象，递归调用继续替换子对象的属性
              replaceObjectProperties(A[key], B[key]);
          } else {
              // 否则直接用A对象的属性值替换B对象的属性值
              B[key] = A[key];
          }
      }
  }
  // return B;
}
